package com.panopset.sf;

import java.awt.Dimension;

import javax.swing.JDialog;
import javax.swing.JFrame;

import com.panopset.sf.env.Screener;

/**
 * Frame centered in the middle of the main screen.
 * Default close operation of JDialog.DISPOSE_ON_CLOSE is also set.
 * 
 * @author Karl Dinwiddie
 * 
 */
public class CenterFrame {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new CenterFrame(new JFrame(), new Dimension(100, 100)).getFrame()
				.setVisible(true);
	}

	/**
	 * Creates a new 600x500 JFrame that is centered in the main screen.
	 */
	public CenterFrame() {
		this(new JFrame(), new Dimension(600, 500));
	}

	/**
	 * Creates a new JFrame that is centered in the main screen.
	 * @param dim Dimensions of new frame.
	 */
	public CenterFrame(Dimension dim) {
		this(new JFrame(), dim);
	}

	/**
	 * Adjusts an existing JFrame so that it is centered in the main screen.
	 * @param frame
	 * @param dim
	 */
	public CenterFrame(final JFrame frame, Dimension dim) {
		f = frame;
		f.setSize(dim);
		f.setLocation(new Screener().centerInScreen(dim));
		f.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
	}

	public JFrame getFrame() {
		return f;
	}

	private final JFrame f;
}
